package com.usdt.system.service.impl.cp;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usdt.system.cp.utils.UserAndDeptUtils;
import com.usdt.system.domain.cp.ClueCustomerInfoEntity;
import com.usdt.system.mapper.cp.ClueCustomerInfoMapper;
import com.usdt.system.service.cp.ClueCustomerInfoService;

/**
 * <p>
 * 线索-客户信息 服务实现类
 * </p>
 *
 * @author L
 * @since 2025-09-30
 */
@Service
public class ClueCustomerInfoServiceImpl extends ServiceImpl<ClueCustomerInfoMapper, ClueCustomerInfoEntity> implements ClueCustomerInfoService {

	@Override
	public List<ClueCustomerInfoEntity> checkClueCustomerInfoUniqueByDeptIdAndPhoneNumber(String deptId,
			String phoneNumber, Integer id) {
		
		return baseMapper.checkClueCustomerInfoUniqueByDeptIdAndPhoneNumber(deptId,phoneNumber,id);
	}

	@Override
	public List<ClueCustomerInfoEntity> getClueCustomerInfoByClueId(Integer clueId) {
		QueryWrapper<ClueCustomerInfoEntity> query = new QueryWrapper<ClueCustomerInfoEntity>();
		query.eq("is_del", false).eq("clue_id", clueId);
		
		return baseMapper.selectList(query);
	}

	@Override
	public void delByClueId(Integer clueId) {
		QueryWrapper<ClueCustomerInfoEntity> query = new QueryWrapper<ClueCustomerInfoEntity>();
		query.eq("is_del", false).eq("clue_id", clueId);
		
		baseMapper.delete(query);
	}

	@Override
	public void transferOut(Integer clueId, String outUserId, String outDeptId, String currentUserId) {
		ClueCustomerInfoEntity entity = new ClueCustomerInfoEntity();
		entity.setCreateBy(outUserId);
		entity.setDeptId(outDeptId);
		entity.setUpdateBy(currentUserId);
		
		QueryWrapper<ClueCustomerInfoEntity> query  = new QueryWrapper<ClueCustomerInfoEntity>();
		query.eq("clue_id", clueId);
		baseMapper.update(entity , query);
	}

	@Override
	public void batchTransferOut(List<Integer> clueIds, String outUserId, String outDeptId) {
		QueryWrapper<ClueCustomerInfoEntity> query = new QueryWrapper<ClueCustomerInfoEntity>();
		query.eq("is_del", false).in("clue_id", clueIds);
		
		ClueCustomerInfoEntity clueCustomerInfoEntity = new ClueCustomerInfoEntity();
		clueCustomerInfoEntity.setDeptId(outDeptId);
		clueCustomerInfoEntity.setCreateBy(outUserId);
		clueCustomerInfoEntity.setUpdateBy(UserAndDeptUtils.getCurrentUserId());
		baseMapper.update(clueCustomerInfoEntity, query);
	}

}
